/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.click.app.webapp.action;

import com.click.app.model.BalanceLaundry;
import com.click.app.model.Laundry;
import com.click.app.model.PaymentsLaundry;
import com.click.app.model.PeriodPaymentLaundry;
import com.click.app.service.LaundryManager;
import com.click.app.service.PeriodPaymentLaundryManager;
import java.util.List;

/**
 *
 * @author arnold
 */
public class PaymentLaundryAction extends BaseAction {
    private Long id;
    private Laundry laundry; 
    private LaundryManager laundryManager;
    private PeriodPaymentLaundryManager periodPaymentLaundryManager;
    private PeriodPaymentLaundry periodPaymentLaundry;
    private List<BalanceLaundry> laundriesBalances;
    private PaymentsLaundry paymentsLaundry;

    public String list() {
        System.out.println("PaymentLaundryAction -> list()");
        if (id != null) {
            laundry = laundryManager.get(id);
            getSession().setAttribute("idLaundry", laundry.getId());
//        } else {
//            employee = (Employee) getSession().getAttribute("employee");
//        }
        }
        if (laundry != null) {
            periodPaymentLaundry = periodPaymentLaundryManager.findCurrentPeriodByLaundry(laundry.getId());
            laundriesBalances = periodPaymentLaundry.getBalanceLaundryList();
//            if (!balancesLaundries.isEmpty()) {
//                lastBalanceId = balances.get(balances.size() - 1).getId();
//            } else {
//                lastBalanceId = 0l;
//            }
//            List<CutProcess> cPs = cutProcessManager.findByEmployeePay(employee);
//            if (cPs != null && cPs.size() > 0) {
//                canAdd = true;
//            }
            System.out.println("PaymentLaundryAction -> end list()");
            return SUCCESS;
        } else {
            System.out.println("PaymentLaundryAction -> error end list()");
            return ERROR;
        }
    }
    public String edit() {
        System.out.println("PaymentLaundryAction -> edit()");
        if(getSession().getAttribute("idLaundry") != null ){
            laundry = laundryManager.get((Long)getSession().getAttribute("idLaundry"));
            periodPaymentLaundry = periodPaymentLaundryManager.findCurrentPeriodByLaundry(laundry.getId());

        }
        System.out.println("PaymentLaundryAction -> end edit()");
        return SUCCESS;
    }

    public String save(){
        System.out.println("PaymentLaundryAction -> save()");
        System.out.println(paymentsLaundry);
        System.out.println("PaymentLaundryAction -> end save()");
        return SUCCESS;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Laundry getLaundry() {
        return laundry;
    }

    public void setLaundry(Laundry laundry) {
        this.laundry = laundry;
    }

    public LaundryManager getLaundryManager() {
        return laundryManager;
    }

    public void setLaundryManager(LaundryManager laundryManager) {
        this.laundryManager = laundryManager;
    }

    public List<BalanceLaundry> getLaundriesBalances() {
        return laundriesBalances;
    }

    public void setLaundriesBalances(List<BalanceLaundry> laundriesBalances) {
        this.laundriesBalances = laundriesBalances;
    }

    public PeriodPaymentLaundry getPeriodPaymentLaundry() {
        return periodPaymentLaundry;
    }

    public void setPeriodPaymentLaundry(PeriodPaymentLaundry periodPaymentLaundry) {
        this.periodPaymentLaundry = periodPaymentLaundry;
    }

    public PeriodPaymentLaundryManager getPeriodPaymentLaundryManager() {
        return periodPaymentLaundryManager;
    }

    public void setPeriodPaymentLaundryManager(PeriodPaymentLaundryManager periodPaymentLaundryManager) {
        this.periodPaymentLaundryManager = periodPaymentLaundryManager;
    }

    public PaymentsLaundry getPaymentsLaundry() {
        return paymentsLaundry;
    }

    public void setPaymentsLaundry(PaymentsLaundry paymentsLaundry) {
        this.paymentsLaundry = paymentsLaundry;
    }
    
}
